import 'package:flutter/material.dart';
import 'package:flutter_module/global/colors.dart';

import 'package:flutter/material.dart';

import 'homePage/views/HomePage.dart';
import 'myPage/MyPage.dart';

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() {
    return _TabsState();
  }
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  PageController _pageController;
  List<Widget> _pageList = [
    HomePage(),
    HomePage(),
    MyPage(),
  ];

  @override
  void initState() {
    super.initState();
    this._pageController = new PageController(initialPage: this._currentIndex);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: PageView(
        controller: this._pageController,
        children: this._pageList,
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.black,
        currentIndex: _currentIndex,
        onTap: (index) {
          //设置底部图标点击选中
          setState(() {
            this._currentIndex = index;
            this._pageController.jumpToPage(index);
          });
        },
        type: BottomNavigationBarType.fixed,
        //显示多个底部菜单
        fixedColor: AppColors.primary,
        items: [
          BottomNavigationBarItem(
            icon: _currentIndex == 0
                ? Image.asset(
                    'assets/images/home_se.png',
                    width: 32,
                    height: 28,
                  )
                : Image.asset(
                    'assets/images/home_un.png',
                    width: 32,
                    height: 28,
                  ),
            title: Text(
              '首页',
              style: TextStyle(
                color: Color(0xffA0A0A0),
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: _currentIndex == 1
                ? Image.asset(
                    'assets/images/mess_se.png',
                    width: 32,
                    height: 28,
                  )
                : Image.asset(
                    'assets/images/mess_un.png',
                    width: 32,
                    height: 28,
                  ),
            title: Text(
              '消息',
              style: TextStyle(
                color: Color(0xffA0A0A0),
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: _currentIndex == 2
                ? Image.asset(
                    'assets/images/my_se.png',
                    width: 32,
                    height: 28,
                  )
                : Image.asset(
                    'assets/images/my_un.png',
                    width: 32,
                    height: 28,
                  ),
            title: Text(
              '我的',
              style: TextStyle(
                color: Color(0xffA0A0A0),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
